package org.rabbitmq.mq02.demo;

import org.rabbitmq.mq02.mqClient.Channel;
import org.rabbitmq.mq02.mqClient.Connection;
import org.rabbitmq.mq02.mqClient.ConnectionFactory;
import org.rabbitmq.mq02.mqServer.core.ExchangeType;

import java.io.IOException;

/**
 * 模拟生产者
 */
public class producer {
    public static void main(String[] args) throws IOException, InterruptedException {
        ConnectionFactory factory = new ConnectionFactory();
        System.out.println("启动生产者");
        factory.setHost("127.0.0.1");
        factory.setPort(9090);
        //创建连接
        Connection connection = factory.newConnection();
        //创建channel
        Channel channel = connection.createChannel();

        //创建交换机 队列 绑定
        channel.exchangeDeclare("exchange", ExchangeType.DIRECT,true,false,null);
        channel.queueDeclare("queue",true,false,null);

        //发送消息
        boolean ok = channel.basicPublish("exchange", "queue",null,"hello".getBytes());
        System.out.println("消息发送成功: ok:"+ok);
        Thread.sleep(1000);
        //关闭资源
        channel.close();
        connection.createChannel();

    }

}
